<template>
  <div class="cms">
    <van-field v-model="title" label="标题" :formatter="formatter" placeholder="在输入时执行格式化" />
    <van-field
      v-model="type"
      label="目录"
      :formatter="formatter"
      format-trigger="onBlur"
      placeholder="在失焦时执行格式化"
    />
    <van-field rows="1" v-model="content" autosize label="答案" type="textarea" placeholder="请输入留言" />
    <van-button type="primary" block @click="postData">确认</van-button>
  </div>
</template>

<script>
import axios from 'axios'
import Qs from 'qs'
axios.defaults.baseURL = 'http://42.194.195.126/api'
// axios.defaults.headers.common['Authorization'] =
//   'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI4ZDc0OWFkMWEyYjY0NGRlYTM1MGY3MzIwNjdmZDk3OCIsInVuIjoiIiwicGYiOiJLU1IiLCJycyI6W10sImV4cCI6MTU5MjcxODUwMX0.1cWeoW2e5QIsr647tPGq6xQn7AD-j766bFNCCXW8RdnmwPCWEI0Pvoh3Crt0sYhABKq8AuDzvJct_v2XkBcSQA'
axios.defaults.headers.post['Content-Type'] =
  'application/x-www-form-urlencoded'
axios.interceptors.request.use(config => {
  console.log(config.data, 'config.data')
  return config
})
export default {
  data() {
    return {
      title: '',
      content: '',
      type: '前端高频面试题',
      value1: '',
      value2: ''
    }
  },
  methods: {
    postData() {
      let data = {}
      data.title = this.title
      data.content = this.content
      data.type = this.type
      console.log('111')

      axios.post(
        `/cms/audition/addAudition`,
        Qs.stringify({
          title: 'sadsad',
          content: 'dsad',
          type: 'sasasa'
        })
      )
    },
    formatter(value) {
      // 过滤输入的数字
      return value.replace(/\d/g, '')
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='scss' scoped>
.cms {
  height: 100%;
  background-color: #e6e6e6;
}
</style>
